import matplotlib.pyplot as plt
import matplotlib.dates as mdate
from scipy.io import wavfile


class PointPicker(object):
    def __init__(self, data):

        self.fig = plt.figure()
        self.ax = self.fig.add_subplot(111)

        self.line = plt.plot(data)

        self.fig.canvas.mpl_connect('pick_event', self.onpick)
        self.fig.canvas.mpl_connect('key_press_event', self.onpress)
        print "TEST"
        self.ax.axvline(x=25000)

    def onpress(self, event):
        """define some key press events"""
        if event.key.lower() == 'q':
            sys.exit()

    def onpick(self,event):
        print "Test"
        x = event.mouseevent.xdata
        y = event.mouseevent.ydata
        L =  self.ax.axvline(x=x)
        self.fig.canvas.draw()


if __name__ == '__main__':
    import numpy as np
    import datetime
    audio = wavfile.read('disconnect_me.wav')
    #plt.ion()
    p = PointPicker(audio[1])
    plt.show()
